home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
a_utils
/
perl
/
msds-prl
/
bcdsprl4.zoo
/
lib
/
shellwor.pl
< prev
next >
Wrap
Text File
|
1991-11-13
|
802b
|
43 lines
#; shellwords.pl
#;
#; Usage:
#; require 'shellwords.pl';
#; @words = &shellwords($line);
#; or
#; @words = &shellwords(@lines);
#; or
#; @words = &shellwords; # defaults to $_ (and clobbers it)
sub shellwords {
package shellwords;
local($_) = join('', @_) if @_;
local(@words,$snippet,$field);
s/^\s+//;
while ($_ ne '') {
$field = '';
for (;;) {
if (s/^"(([^"\\]+|\\[\\"])*)"//) {
($snippet = $1) =~ s#\\(.)#$1#g;
}
elsif (s/^'(([^'\\]+|\\[\\'])*)'//) {
($snippet = $1) =~ s#\\(.)#$1#g;
}
elsif (s/^\\(.)//) {
$snippet = $1;
}
elsif (s/^([^\s\\'"]+)//) {
$snippet = $1;
}
else {
s/^\s+//;
last;
}
$field .= $snippet;
}
push(@words, $field);
}
@words;
}
1;